#ifndef __CONVERT_HPP__
#define __CONVERT_HPP__

/**
 *  This file is part of PennerBot
 *
 *  Copyright (C) 2010 microkernel
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include <string>
#include <sstream>


namespace PBot
{
namespace Core
{


template <typename T>
T StrToVar(const std::string& str)
{
    T result;
    std::stringstream stream;
    stream << str;
    stream >> result;

    return result;
}

template <typename T>
std::string NumToStr(T num)
{
   std::string result;
   std::stringstream stream;
   stream << num;
   stream >> result;

   return result;
}

inline void RemoveDelimiters(std::string& str, bool american)
{
    if(american)
    {
        size_t pos = 0;

        while((pos = str.find(','), pos) != std::string::npos)
        {
            str.erase(pos, 1);
        }
    }
    else
    {
        size_t pos = 0;

        while((pos = str.find('.'), pos) != std::string::npos)
        {
            str.erase(pos, 1);
        }

        while((pos = str.find(','), pos) != std::string::npos)
        {
            str.replace(pos, 1, 1, '.');
        }
    }
}

}
}

#endif // __CONVERT_HPP__
